package com.ai.tikai.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;

import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    // 1. 声明队列
    @Bean
    public Queue myQueue() {
        // durable: 是否持久化, 默认是 true
        // exclusive: 是否独占, 默认是 false
        // autoDelete: 是否自动删除, 默认是 false
        return new Queue("my-queue", true);
    }

    // 2. 声明交换机 (这里使用 Direct Exchange)
    @Bean
    public DirectExchange myDirectExchange() {
        return new DirectExchange("my-direct-exchange", true, false);
    }

    // 3. 声明绑定关系：将队列和交换机绑定起来，并指定一个路由键 (Routing Key)
    @Bean
    public Binding bindQueueToExchange() {
        return BindingBuilder.bind(myQueue()).to(myDirectExchange()).with("my-routing-key");
    }
}
